<?php

class Departments_model extends CI_Model {

    function  __construct() {
        parent::__construct();
        $this->tableName = 'set_departments';
        $this->load->model("functions_model");
    }

    function delete($tid) {
        $data['tid'] = $tid;
        $this->db->where($data);
        $this->db->delete($this->tableName);
    }

    function newDepartment($added_by) {
        $data = $_POST;
        $data['added_by'] = $added_by;
        $this->db->insert($this->tableName, $data);
    }

    function getAll() {
        $this->db->select('tid,added_by,name, date_added');
        $this->db->from($this->tableName);
        $this->db->order_by("tid", "desc");
        $query = $this->db->get();
        $result = array();
        foreach ($query->result_array() as $row) {
            $row['date_added'] = $this->functions_model->prettyDateTime($row['date_added']);
            $row['links'] = "<a href='javascript:gotoUrl(\"" . base_url() . "index.php?/admin_settings/deleteSbu/".$row['tid']."\",\"Are you sure to delete this record?\")'>Delete</a>";
            unset ($row['tid']);
            $result[] = $row;
        }
        return $result;
    }

}

?>
